package com.tms.mail.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.tms.mail.domain.Mail;
import com.tms.mail.service.IMailService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 油费管理Controller
 *
 * @author ruoyi
 * @date 2024-11-01
 */
@RestController
@RequestMapping("/mail")
public class MailController extends BaseController
{
    @Autowired
    private IMailService mailService;

    /**
     * 查询油费管理列表
     */
    @RequiresPermissions("mail:mail:list")
    @GetMapping("/list")
    public TableDataInfo list(Mail mail)
    {
        startPage();
        List<Mail> list = mailService.selectMailList(mail);
        return getDataTable(list);
    }

    /**
     * 导出油费管理列表
     */
    @RequiresPermissions("mail:mail:export")

    @PostMapping("/export")
    public void export(HttpServletResponse response, Mail mail)
    {
        List<Mail> list = mailService.selectMailList(mail);
        ExcelUtil<Mail> util = new ExcelUtil<Mail>(Mail.class);
        util.exportExcel(response, list, "油费管理数据");
    }

    /**
     * 获取油费管理详细信息
     */
    @RequiresPermissions("mail:mail:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mailService.selectMailById(id));
    }

    /**
     * 新增油费管理
     */
    @RequiresPermissions("mail:mail:add")

    @PostMapping
    public AjaxResult add(@RequestBody Mail mail)
    {
        return toAjax(mailService.insertMail(mail));
    }

    /**
     * 修改油费管理
     */
    @RequiresPermissions("mail:mail:edit")

    @PutMapping
    public AjaxResult edit(@RequestBody Mail mail)
    {
        return toAjax(mailService.updateMail(mail));
    }

    /**
     * 删除油费管理
     */
    @RequiresPermissions("mail:mail:remove")

	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mailService.deleteMailByIds(ids));
    }
}
